package com.dgshanger.sanhxiaofeisc.mvp.model

import com.blankj.utilcode.util.EncryptUtils
import com.dgshanger.sanhxiaofeisc.common.AppApi
import com.dgshanger.sanhxiaofeisc.entity.LoginEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.LoginContract
import com.dgshanger.sanhxiaofeisc.ui.login.LoginActivity
import com.xx.baseutilslibrary.network.rx.RxHelper
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * LoginModel
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/2/5 17:19.
 */

class LoginModel : LoginContract.Model {

    override fun login(loginType: Int, mobile: String?, login_pass: String?, httpObserver: XxBaseHttpObserver<LoginEntity>?) {
        (if (loginType == LoginActivity.QUICK_LOGIN)
            AppApi.Api()
                    .mobile_login(mobile, login_pass)
        else
            AppApi.Api()
                    .login(mobile, EncryptUtils.encryptMD5ToString(login_pass).toLowerCase()))
                .compose(RxHelper.io_main())//线程调度
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }

    override fun sendCode(mobile: String?, httpObserver: XxBaseHttpObserver<Any>?) {
        AppApi.Api()
                .get_pin(mobile, "app_mobile_login")
                .compose(RxHelper.io_main())//线程调度
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }

}
